﻿using System;
using System.Collections.Generic;
using System.Text;

namespace EmbeddedSharp.Core {
    public class ListNode : FuncNode {

        public ListNode()
            : base() {
            base.Value = "list";
        }

        public override object Evaluate() {
            ListObject list = new ListObject();

            for(int index = Parameters.Count-1;
                index>=0;
                --index) {
                list.Add(Parameters[index].Evaluate());
            }

            return list;
        }

        //public static ListNode operator +(ListNode ln)
        //{
        //    ListNode result = new ListNode();

        //    if (ln.Children.Count != this.Children.Count)
        //    {
        //        throw new ArgumentException(
        //            "The count of children are not the same.");
        //    }

        //    for (int index = 0; index < Children.Count; index++)
        //    {
        //        if (Children[index] is FuncNode)
        //        {
        //        }
        //        else if (Children[index] is ListNode)
        //        {
        //        }
        //        else if (Children[index] is NumberNode)
        //        {
        //        }
        //        else
        //        {
        //        }
        //    }
        //    return result;
        //}

        public override string ToString() {
            StringBuilder buff = new StringBuilder();

            buff.Append("[");
            for(int index = Parameters.Count-1; 
                index >=0; --index) {
                object value = Parameters[index].Evaluate();
                buff.Append(value);
                if (index > 0) {
                    buff.Append(",");
                }
            }
            buff.Append("]");

            return buff.ToString();
        }
    }
}
